import requests
from bs4 import BeautifulSoup


def get_page(url):
    r = requests.get(url)
    html = r.text
    soup = BeautifulSoup(html, "html.parser")

    title = soup.title.string

    menu_html = soup.find("ul", class_="list-group list-group-flush")

    # 从左侧菜单 html 内容中获取所有菜单信息，并且按照（url，展示问诊）的格式返回
    menu_info = [(a['href'], a.string) for a in menu_html.find_all("a")]
    return title, menu_info


if __name__ == '__main__':
    url = 'https://python-abc.xyz/basic/5642/'
    title, menu_info = get_page(url)
    print('文章标题为：', title)
    print('菜单列表如下：')
    for menu in menu_info:
        print('链接：{}；标题：{}'.format(*menu))